package com.ml.customannotation.aop.biz.impl;

import com.google.common.base.Preconditions;
import com.ml.customannotation.aop.biz.TestCustomAnno;
import com.ml.customannotation.aop.customAnnotation.Biz;
import com.ml.customannotation.aop.customAnnotation.BizTemplate;
import com.ml.customannotation.aop.customAnnotation.NoCheck;
import org.springframework.stereotype.Service;

import javax.rmi.CORBA.Util;
import java.util.Objects;

/**
 * @author zhaozongyi@mmears.com
 * @date 2021-05-17
 * @time 12:11
 */
@Service
public class TestCustomAnnoImpl implements TestCustomAnno {
    private static final String EMPTY_MSG = " is empty.";

    @Override
    @Biz
    public String test1(String a) {
        System.out.println(a + "HELLO1");
        return a;
    }

    @Override
    @Biz(checkParam = false)
    public String test2(String ac, Integer bd) {
        System.out.println(ac + "HELLO2" + bd);
        return ac;
    }

    @Override
    @Biz
    public String test3(String abc, Integer bbb, @NoCheck Util util) {
        System.out.println(abc + "HELLO3");
        return abc;
    }

    @Override
    public String test5(String abc, Integer bbb, Util util) {

        return new BizTemplate<String>() {

            @Override
            protected void checkParams() {
                try {
                    Preconditions.checkArgument(Objects.nonNull(abc), abc + EMPTY_MSG);
                    Preconditions.checkArgument(Objects.nonNull(bbb), bbb + EMPTY_MSG);
                }catch(Exception e){

                }
            }

            @Override
            public String process() throws Throwable {
                System.out.println(abc + "HELLO5");
                return abc;
            }

        }.execute();

    }


    @Override
    @Biz
    public String test4() {
        System.out.println("HELLO4");
        return "4";
    }


}
